// connections.h: Connections information

#ifndef connections_h_
#define connections_h_

#ifdef __18F8520
	#define Robot2005
#elif defined(__18F8722)
	//#define Robot2006
	#define Robot2007
#else
	#error Unknown processor defined
#endif

#if !defined(Robot2005) && !defined(Robot2006) && !defined(Robot2007)
#error Undeclared Robot
#endif



//**************  FRC CONNECTIONS *****************

//  PWM definitions

#ifdef Robot2005
	#define mPWMcimLeft		pwm01
	#define mPWMfpriceLeft	pwm02
	#define mPWMcimRight	pwm03
	#define mPWMfpriceRight pwm04

	#define mPump			relay2_fwd	//on separate power circuit
#endif

#ifdef Robot2006
	#define mPWMRightCIM		pwm01
	#define mPWMLeftCIM			pwm02
#elif defined Robot2007
	#define mPWMLeftCIM			pwm11
	#define mPWMRightCIM		pwm12
#endif

#ifdef Robot2007
	#define mPWMLift			pwm03
	#define mRelayArmUp			relay1_fwd
	#define mRelayArmDown		relay1_rev
	#define mRelayFingerOpen	relay2_fwd
	#define mRelayFingerClose	relay2_rev
#endif

#define mPump					relay3_fwd


//*** Analog Inputs ***********************************************
#define mLiftPotPort			rc_ana_in01
#define mProximityLeftPort		rc_ana_in10
#define mProximityRightPort		rc_ana_in11

// ADJUSTMENT POTS
#define mUserPot1Port			rc_ana_in16
//*** End of Analog Inputs ****************************************


// Digital Inputs:
#ifdef Robot2006
	#define mLeftEncoderBCount	rc_dig_in01
	#define mRightEncoderBCount	rc_dig_in02
#elif defined Robot2007
	#define mLeftEncoderBCount	rc_dig_in07
	#define mRightEncoderBCount	rc_dig_in08
	#define mSwGripperTrap	!rc_dig_in15
#endif


// Interrupts - won't appear in code. Level changes on these pins
// will be handled in interruptHandlers.c
#define mLeftEncoderCount	rc_dig_in03
#define mRightEncoderCount	rc_dig_in04


#ifdef Robot2007
	#define mSwLimitLiftLow		!rc_dig_in16//rc_dig_in09
	#define mSwLimitLiftHigh	!rc_dig_in17//rc_dig_in08

	#define mLEDDataOut rc_dig_in10	//Configure as output
	#define mLEDClock rc_dig_in11	//Configure as output
	#define mLEDDataReady rc_dig_in12	//Configure as output
#endif

#define mSwPressure			rc_dig_in18

//**************  END of FRC CONNECTIONS *****************



//**************  OPERATOR INTERFACE CONNECTIONS *****************

#define mXboxLeft			p2_y
#define mXboxRight			p2_x
#define mXboxA				p2_sw_trig
#define mXboxB				p2_sw_top
#define mXboxX				p2_sw_aux1
#define mXboxY				p2_sw_aux2
#define mXboxLT				((p2_wheel & 0x80) == 0)
#define mXboxRT				((p2_wheel & 0x40) == 0)
#define mXboxLB				((p2_wheel & 0x20) == 0)
#define mXboxRB				((p2_wheel & 0x10) == 0)
#define mXboxBack			((p2_aux & 0x80) == 0)
#define mXboxStart			((p2_aux & 0x40) == 0)
#define mXboxCenterX		((p2_aux & 0x20) == 0)
#define mXboxDUp			((p2_aux & 0x10) == 0)

#ifdef Robot2006
	#define mJoyRightCIM		p1_y
	#define mJoyLeftCIM			p2_y
	#define mJoyForward			p2_y
	#define mJoyTurn			p1_x
#elif defined Robot2007
	#define mJoyLeftCIM			mXboxLeft
	#define mJoyRightCIM		mXboxRight
	#define mJoyForward			mXboxLeft
	#define mJoyTurn			mXboxRight
#endif

#define mReverseRobot		0//p1_sw_aux1
#define mMetaButton			mXboxCenterX

#ifdef Robot2007
	#define mSwXboxManualMode	p4_sw_aux1
	
	#define mBtnReadyPickup		(mSwXboxManualMode ? 0 : mXboxA)
	#define mBtnLiftL0			(mSwXboxManualMode ? mXboxA : 0)
	#define mBtnLiftL1			mXboxB
	#define mBtnLiftL2			mXboxX
	#define mBtnLiftL3			mXboxY
	
	#define mBtnScore			(mSwXboxManualMode ? mXboxDUp : mXboxRT)
	#define mBtnAutoAim			(mSwXboxManualMode ? 0 : mXboxRB)
	#define mBtnUnspoil			(mSwXboxManualMode ? 0 : mXboxLT)
	#define mBtnAbort			mXboxCenterX
	
	#define mBtnLiftUp			(mSwXboxManualMode ? p3_sw_trig||mXboxLB	: p3_sw_trig)
	#define mBtnLiftDown		(mSwXboxManualMode ? p3_sw_top||mXboxRB		: p3_sw_top)
	#define mBtnArmUp			(mSwXboxManualMode ? p3_sw_aux1||mXboxBack	: p3_sw_aux1)
	#define mBtnArmDown			(mSwXboxManualMode ? p3_sw_aux2||mXboxStart	: p3_sw_aux2)
	#define mBtnFingerOpen		(mSwXboxManualMode ? p4_sw_trig||mXboxLT	: p4_sw_trig)
	#define mBtnFingerClose		(mSwXboxManualMode ? p4_sw_top||mXboxRT		: p4_sw_top)
	
	#define mBtnPotLift			p1_sw_trig
	
	#define mBtnDeployRamps		p4_sw_aux2
	
	#define mBtnSetLiftPreset	mXboxBack && mXboxStart && mMetaButton
#endif

//**********************************

#ifdef Robot2006
	#define mTurnPot1		p3_x		// Pan Offset on 2006
	#define mTurnPot2		p3_y
#elif defined Robot2007
	#define mTurnPot1		p4_y
	#define mTurnPot2		p3_y
#endif

#define mUserOIPot1			p3_x
#define mUserOIPot2			p3_y
#define mUserOIPot3			p3_wheel

// must be in UserDisplay mode with META down for drive option selection
#ifdef Robot2006
	#define mRawDriveBtn			p3_sw_aux1	// mPanLeftSw on 2006
	#define mDriveMethodBtn			p3_sw_aux2 // mPanRightSw on 2006
#elif defined Robot2007
	#define mRawDriveBtn			mXboxLB
	#define mDriveMethodBtn			mXboxRB
#endif

//**************  END of OPERATOR INTERFACE CONNECTIONS *****************



//******************* DASH Board User Bytes *********************************************

//#define kUB_CWSpeed		User_Byte1
//#define kUB_CCWSpeed	User_Byte1

//#define xxx User_Byte3	/* This byte is now used for breaker panel byte 3 */
//#define xxx User_Byte4	/* This byte is now used for breaker panel byte 4 */
//#define xxx User_Byte5	/* This byte is now used for breaker panel byte 5 */
//#define xxx User_Byte6	/* This byte is now used for breaker panel byte 6 */

//********************************************************************************

//enum { kDown=-1, kOff=0, kUp=1};	// 3-way switch

#define mSLEDGripperArmFwd		gSerialLED.green1
#define mSLEDGripperArmRev		gSerialLED.red1
#define mSLEDGripperGripFwd 	gSerialLED.green2
#define mSLEDGripperGripRev		gSerialLED.red2

#define mSLEDLiftStalled		gSerialLED.red4
#define mSLEDLiftCooling		gSerialLED.green4

#define mSLEDGripperTrap		gSerialLED.red5

#define mSLEDLiftLimitLow		gSerialLED.red6
#define mSLEDLiftLimitHigh		gSerialLED.green6

#define mSLEDProximityLeft0		gSerialLED.red7
#define mSLEDProximityLeft1		gSerialLED.green7
#define mSLEDProximityRight0	gSerialLED.red8
#define mSLEDProximityRight1	gSerialLED.green8

#endif //connections_h_	NO CODE BELOW THIS LINE
